//
//  JJPlaneViewController.m
//  MyAnimations
//
//  Created by jxf on 15/12/24.
//  Copyright © 2015年 JJ.sevn. All rights reserved.
//

#import "JJPlaneViewController.h"

@interface JJPlaneViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *plane;

@end

@implementation JJPlaneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupAnimate];
}

- (void)setupAnimate
{
    CGPoint oriPoint = self.plane.center;
    
    [UIView animateKeyframesWithDuration:1.5 delay:0 options:0 animations:^{
        
        // 注意startTime和relativeDuration是指相对duration的相对时间,在0和1之间取值
        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5 animations:^{
           
            CGPoint center = self.plane.center;
            center.x = 300;
            center.y = 200;
            self.plane.center = center;
        }];
        
        [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
            CGPoint center = self.plane.center;
            center.x = 50;
            center.y = 400;
            self.plane.center = center;
        }];

        [UIView addKeyframeWithRelativeStartTime:0.9 relativeDuration:0.5 animations:^{
            
            CGPoint center = self.plane.center;
            center.x = 300;
            center.y = 600;
            self.plane.center = center;
        }];
        
        
    } completion:^(BOOL finished) {
       
        self.plane.center = oriPoint;
        [self setupAnimate];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)backHome:(UIBarButtonItem *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
@end
